package com.itheima.service.impl;

import com.itheima.dto.MemberLoginDTO;
import com.itheima.mapper.UserMemberMapper;
import com.itheima.pojo.Member;
import com.itheima.service.UserMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Date;
import java.util.Objects;

@Service
public class UserMemberServiceImpl implements UserMemberService {
    @Autowired
    UserMemberMapper userMemberMapper;
    /**
     * 会员登录
     * @param memberLoginDTO
     */
    @Override
    public Member login(MemberLoginDTO memberLoginDTO) {
       //查询是否是会员，不是则注册
        Member member = userMemberMapper.memberExit(memberLoginDTO.getTelephone());
        if (Objects.isNull(member)) {
            Member addmember=Member.builder().phoneNumber(memberLoginDTO.getTelephone()).regTime(new Date()).build();
            userMemberMapper.insertMember(addmember);
            return addmember;
        }
        return member;
    }
}
